package com.heima.tess4j;

import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

public class TessForjApplication {
    public static void main(String[] args) throws TesseractException {
//        获取本地图片
        File file = new File("D:\\songs\\Snipaste_2022-09-05_19-36-03.jpg");
//        创建Tesseract对象
        Tesseract tesseract = new Tesseract();
//        设置字体库路径
        tesseract.setDatapath("D:\\workspace\\tessdata");
//        中文识别
        tesseract.setLanguage("chi_sim");
//        执行ocr
        String s = tesseract.doOCR(file);
        System.out.println(s);
        System.out.println("=========");
//        替换回车和tal键
        String s1 = s.replaceAll("\\r|\\n", "-").replaceAll(" ", "");
        System.out.println(s1);
    }
}
